﻿using PmSoft.ApplicationContext;
using PmSoft.Entity;

namespace PmSoft.Events;

/// <summary>
/// 通用事件参数
/// </summary>
[Serializable]
public class CommonEventArgs : EventArgs
{
    private readonly IApplicationContext applicationContext;

    public CommonEventArgs(IApplicationContext applicationContext)
    {
        this.applicationContext = applicationContext;
    }

    /// <summary>
    /// 构造函数 建议使用EventOperationType协助输入，例如：EventOperationType.Instance().Create() 
    /// </summary>
    /// <param name="eventOperationType">事件操作类型</param>
    public CommonEventArgs(IApplicationContext applicationContext, string eventOperationType)
    {
        this.EventOperationType = eventOperationType;
        this.User = applicationContext.CurrentUser;
        this.ClientIp = applicationContext.ClientIp;
        this.Url = applicationContext.RequestUrl;
    }

    public CommonEventArgs(IApplicationContext applicationContext, string eventOperationType, IUser user)
    {
        this.ClientIp = applicationContext.ClientIp;
        this.Url = applicationContext.RequestUrl;
        this.EventOperationType = eventOperationType;
        this.User = user;
    }

    /// <summary>
    /// 事件操作类型
    /// </summary>
    public string EventOperationType { get; set; }

    /// <summary>
    /// 操作IP
    /// </summary>
    public string ClientIp { get; set; }

    /// <summary>
    /// 操作URL
    /// </summary>
    public string Url { get; set; }

    /// <summary>
    /// 操作人信息
    /// </summary>
    public IUser User { get; set; }
}
